package example1;

// 测试线程礼让
// 礼让不一定成功
public class TestYield {

    public static void main(String[] args) {
        myYield myYield=new myYield();
        new Thread(myYield,"A").start();
        new Thread(myYield,"B").start();
    }
}


class myYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " 线程开始执行");
        Thread.yield(); // 礼让
        System.out.println(Thread.currentThread().getName() + " 线程停止执行");
    }
}